package com.boge.config;

import com.boge.store.RedisChatMemoryStore;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ChatMemoryConfig {

    @Autowired
    private OpenAiChatModel chatModel;

    @Autowired
    private RedisChatMemoryStore store;

/*    @Bean
    public ChatBotService chatBotService(){
        return AiServices.builder(ChatBotService.class)
                .chatModel(chatModel)
                .build();

    }*/

    @Bean
    public ChatMemory chatMemory(){
        return MessageWindowChatMemory.builder()
                .maxMessages(20) // 记忆最多的条数
                .build();
    }
    @Bean
    public ChatMemoryProvider chatMemoryProvider(){
        return new ChatMemoryProvider() {
            @Override
            public ChatMemory get(Object memoryId) {
                return MessageWindowChatMemory.builder()
                        .maxMessages(20)
                        .id(memoryId) // 绑定会话id
                        .chatMemoryStore(store) // 定义持久化的方案
                        .build();
            }
        };
    }
}
